/*NOTICE

This software was produced for the U. S. Government
under Contract No. FA8721-09-C-0002, and is
subject to the Rights in Noncommercial Computer Software
and Noncommercial Computer Software Documentation Clause
(DFARS) 252.227-7014 (JUN 1995)

(c) 2009 The MITRE Corporation. All Rights Reserved.
*/
package org.mitre.xmltransform.xsd;

import java.io.File;

import org.mitre.xmltransform.XPathNamespaceContextImpl;
import org.mitre.xmltransform.XmlInputDocument;
import org.w3c.dom.Node;

public class XsdInputDocument extends XmlInputDocument {
	public XsdInputDocument(File pInputFile) {
		super(pInputFile);
	}
	
	public Node getTypeNode(Node pContext, String pTypeName) {
		String localName; //, prefix; //, namespaceUri;
		
		int pos = pTypeName.indexOf(":");
		if (pos == -1) {
			//prefix = "";
			localName = pTypeName;
			//if (super.getInputValue(pContext, "ancestor::node()[@xmlns='http://www.w3.org/2001/XMLSchema']") != null) {
			if (pContext.getOwnerDocument().isDefaultNamespace("http://www.w3.org/2001/XMLSchema")) {
				return null;
			}
		} else {
			//prefix = pTypeName.substring(0, pos);
			localName = pTypeName.substring(pos + 1);
			//namespaceUri = pContext.getOwnerDocument().lookupNamespaceURI(prefix);
			
		}
		Node result = super.getInputNode("//xs:complexType[@name='" + localName + "']");
		return result;
	}
	
	public Node getType(String pTypeName) {
		String typeName = pTypeName;
		int colonPos = typeName.indexOf(":");
		if (colonPos != -1) {
			typeName = typeName.substring(colonPos + 1);
		}
		return super.getInputNode("//node()[@name='" + typeName + "'][local-name()='complexType' or local-name()='simpleType']");
	}
	
	public boolean isTypeNodeComplex(Node pTypeNode) {
		return pTypeNode.getLocalName().equals("complexType") 
			&& pTypeNode.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema");
	}

	@Override
	protected void addNamespaces(XPathNamespaceContextImpl pNamespaces) {
		pNamespaces.addPrefix("xs", "http://www.w3.org/2001/XMLSchema");
	}

	@Override
	public String buildNodeName(Node context, String fixedPrefix) {
		// TODO Auto-generated method stub
		return null;
	}

}
